package com.apicloud.moduleDemo;

import java.util.List;

import com.apicloud.pkg.sdk.R;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import sdk.pay.PayTypeModel;

/**
 * Created by Joe_PC on 2016/2/16,
 * For MyApplication.
 */
public class PayTypeAdapter extends BaseAdapter {
    private List<PayTypeModel> mArrayList;
    private LayoutInflater mInflater;


    public PayTypeAdapter(Context context, List<PayTypeModel> arrayList) {
        mArrayList = arrayList;
        mInflater = LayoutInflater.from(context);
    }


    @Override
    public int getCount() {
        return mArrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return mArrayList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_listviewlayout, null);
            holder = new ViewHolder();
            holder.image_junpay_type = (ImageView) convertView.findViewById(R.id.image_junpay_type);
            holder.TextView_junpay_type_name = (TextView) convertView.findViewById(R.id.TextView_junpay_type_name);
            holder.TextView_junpay_type_tips = (TextView) convertView.findViewById(R.id.TextView_junpay_type_tips);
            holder.ImageButton_junpay_type_Checked = (ImageView) convertView.findViewById(R.id.ImageButton_junpay_type_Checked);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        switch (mArrayList.get(position).getTypeid()) {
            case "1":
                break;
            case "2":
                break;
            case "3":
                holder.image_junpay_type.setImageResource(R.drawable.u43);
                break;
            case "4":
                holder.image_junpay_type.setImageResource(R.drawable.u29);
                break;
            case "5":
                break;
        }
        holder.TextView_junpay_type_name.setText(String.format("%s", mArrayList.get(position).getTypename()));
        String contactWay = mArrayList.get(position).getContactWay();
        String description = "暂无";
        if (!TextUtils.isEmpty(contactWay)) {
            description = contactWay;
        }
        holder.TextView_junpay_type_tips.setText(String.format("%s", description));

        return convertView;
    }

    private static final class ViewHolder {
        ImageView image_junpay_type;
        TextView TextView_junpay_type_name;
        TextView TextView_junpay_type_tips;
        ImageView ImageButton_junpay_type_Checked;
    }
}
